/**
 * @author Jesse McCane
 * @author Berkley Shands
 */

/*
 * This class deals with a single card and its features
 */

public class Card{
	private int rank, suit;

	Card(int r, int s){
		this.rank = r;
		this.suit = s;
	}

	// returns the rank of the card
	public int getRank(){
		return rank;
	}

	//returns the suit of the card
	public int getSuit(){
		return suit;
	}

	public int getSortVal(){
		return((13 * (suit - 2)) + rank);
	}

	//returns a string containing the rank and suit of the card
	public String toString(){
		return(Deck.ranks[rank] + " of " + Deck.suits[suit]);
	}

	//checks to see if the current card is the ace of hearts or not
	public boolean isAOH(){
		if((this.rank == Gameplay.ACE) && (this.suit == Gameplay.HEARTS)){
			return true;
		}

		return false;
	}

	//checks the current card with the one passed it to see if they are equal
	public boolean equals(Card card){
		if(this.suit == card.getSuit() && this.rank == card.getRank()){
			return true;
		}

		return false;
	}

	//Return TRUE if newCard>currentBest GIVEN roundTrump
	//FALSE if newCard<currentBest GIVEN roundTrump	
	public boolean compareTo(Card otherCard){
		int trump = Gameplay.roundTrump;

		if(trump == Gameplay.ALLTRUMP){
			if(Deck.trumpRanks[otherCard.getRank()] > Deck.trumpRanks[this.rank]){ //new card is greater
				return true;
			}else if(Deck.trumpRanks[otherCard.getRank()] == Deck.trumpRanks[this.rank]){//same rank
				if(otherCard.isAOH()){ //aoh will always win
					return true;
				}else{
					return false;
				}
			}else{ //new card is less than
				return false;
			}
		}else{
			if((this.suit == trump) || (this.isAOH())){ //checks this card is trump
				if((otherCard.isAOH()) || (otherCard.getSuit() == trump)){//checks other card is trump
					if(Deck.trumpRanks[this.rank] > Deck.trumpRanks[otherCard.getRank()]){//this card is highe rank
						return false;
					}else if(Deck.trumpRanks[this.rank] == Deck.trumpRanks[otherCard.getRank()]){//both are the same rank
						if(otherCard.isAOH()){ //aoh wins in that case
							return true;
						}else{
							return false;
						}
					}else{//new card is greater
						return true;
					}
				}else{ //other card isnt trump
					return false;
				}
			}else{ //this card isnt trump
				if((otherCard.getSuit() == trump) || (otherCard.isAOH())){ //other card is trump, smash!
					return true;
				}else{ //neither card is trump
					if(this.suit == otherCard.getSuit()){//check suits
						if((this.suit == Gameplay.CLUBS) || (this.suit == Gameplay.SPADES)){ //black suit comparison
							if(Deck.noTrumpBlack[this.rank] >= Deck.noTrumpBlack[otherCard.getRank()]){
								return false;
							}else{
								return true;
							}
						}else{//red suit comparison
							if(Deck.noTrumpRed[this.rank] >= Deck.noTrumpRed[otherCard.getRank()]){
								return false;
							}else{
								return true;
							}
						}
					}else{ //cards arent the same suit
						return false;
					}
				}
			}
		}
	}

	//Return TRUE if newCard >= currentBest GIVEN suit rankings
	//FALSE if newCard < currentBest GIVEN suit rankings
	public boolean compareToGenaric(Card otherCard){
		int trump = Gameplay.roundTrump;
		int thisRanking, otherRanking;

		if((this.suit == trump) || (this.isAOH()) || trump == Gameplay.ALLTRUMP){ //checks this card is trump
			thisRanking = Deck.trumpRanks[this.rank] + 13;
		}else if((this.suit == Gameplay.CLUBS) || (this.suit == Gameplay.SPADES)){ //black suit comparison
			thisRanking = Deck.noTrumpBlack[this.rank];
		}else{
			thisRanking = Deck.noTrumpRed[this.rank];
		}

		if((otherCard.getSuit() == trump) || (otherCard.isAOH()) || trump == Gameplay.ALLTRUMP){ //checks this card is trump
			otherRanking = Deck.trumpRanks[otherCard.getRank()] + 13;
		}else if((otherCard.getSuit() == Gameplay.CLUBS) || (otherCard.getSuit() == Gameplay.SPADES)){ //black suit comparison
			otherRanking = Deck.noTrumpBlack[otherCard.getRank()];
		}else{
			otherRanking = Deck.noTrumpRed[otherCard.getRank()];
		}

		if(otherRanking >= thisRanking){
			return true;
		}

		return false;
	}
}
